<?php
namespace app\index\controller;
use app\index\controller\BaseController;
use Curl\Curl;
use think\Config;
use think\Request;

/**
 * 投融
 * Class Industry
 * @package app\index\controller
 */
class Invest extends BaseController
{
    /**
     * 投融列表
     */
    public function investlist(){
        $reqData['organ_id'] = $this->request->get('organ_id');
        $reqData['industry_id'] = $this->request->get('industry_id');
        $reqData['city_id'] = $this->request->get('city_id');
        $reqData['chain_id'] = $this->request->get('chain_id');
        $keywords = $this->request->get('keywords','');
        $act = $this->request->get('act');
        $method = $this->request->method();
        $page = $this->request->get('page',0);
        $limit = $this->request->get('limit',10);
        $dispatch = $this->request->dispatch();

        // 业务
        $request_arr = ['page'=>$page,'limit'=>$limit,'act'=> $act,'industry_id' => $reqData['industry_id'],'city_id' => $reqData['city_id'], 'organ_id' => $reqData['organ_id'], 'chain_id'=> $reqData['chain_id'], 'keywords'=>$keywords ];
        $curl_data = $this->getBusiness('Common')->curl_request_data($method,$request_arr);
        if ($curl_data['status'] != 1){
            $this->result['status'] = $curl_data['status'];
            $this->result['msg'] = $curl_data['msg'];
            return json_encode($this->result);
        }

        // 我的收藏字段
        $type = Config::get('collect.5');
        if ($act == 'organ'){
            $type = Config::get('collect.6');
        }
        $return_data = $this->getBusiness('Common')->clickCollet($dispatch,$curl_data['data']['data']['data'],$type);
        $curl_data['data']['data']['data'] = $return_data;

        $this->result['status'] = 1;
        $this->result['data'] = $curl_data['data']['data'];
        return json_encode($this->result);
    }

    /**
     * 投融详情
     * @return false|string
     */
    public function investDetail()
    {
        $reqData['identification'] = $this->request->get('identification');
        $reqData['act'] = $this->request->get('act');
        $reqData['method'] = $this->request->method();
        $dispatch = $this->request->dispatch();
//        if(!preg_match('/^([1-9][0-9]*){1,10}$/', $reqData['identification']))
//        {
//            $this->result['status'] = -1;
//            $this->result['msg'] = '参数错误';
//            return json_encode($this->result);
//        }
        if (!$reqData['identification']){
            $this->result['status'] = -1;
            $this->result['msg'] = '参数错误';
            return json_encode($this->result);
        }

        // 业务
        $curl_data = $this->getBusiness('Common')->curl_request_data($reqData['method'] ,array('identification' => $reqData['identification'],'act' => $reqData['act']));
        if ($curl_data['status'] != 1){
            $this->result['status'] = $curl_data['status'];
            $this->result['msg'] = $curl_data['msg'];
            return json_encode($this->result);
        }

        // 我的收藏字段
        $type = Config::get('collect.5');
        if ($reqData['act'] == 'organ'){
            $type = Config::get('collect.6');
        }
        $single = array($curl_data['data']['data']);
        $return_data = $this->getBusiness('Common')->clickCollet($dispatch,$single,$type);
        $curl_data['data']['data'] = $return_data;

        $this->result['status'] = 1;
        $this->result['msg'] = 'success';
        $this->result['data'] = $curl_data['data']['data'];
        return json_encode($this->result);
    }

    /**
     * 智库列表
     */
    public function tankList()
    {
        $reqData['act'] = $this->request->get('act');
        $reqData['organ_id'] = $this->request->get('organ_id');
        $reqData['industry_id'] = $this->request->get('industry_id');
        $reqData['city_id'] = $this->request->get('city_id');
        $reqData['chain_id'] = $this->request->get('chain_id');
        $keywords = $this->request->get('keywords','');
        $method = $this->request->method();
        $page = $this->request->get('page',0);
        $limit = $this->request->get('limit',10);
        $dispatch = $this->request->dispatch();

        if ($reqData['act'] == 'organ'){
                // 机构数据
                $url = Config::get('cloude.url') .Config::get('cloude.Company')['companylist'];
                $request_arr = ['page'=>$page,'limit'=>$limit,'chain_id'=>$reqData['chain_id'],'industry_id' => $reqData['industry_id'],'city_id' => $reqData['city_id'],'tank_id'=>1, 'keywords'=>$keywords ];
                $curl_arr  = httpRequest($url,$method,$request_arr);
                if (!$curl_arr){
                    $this->result['status'] = -1;
                    $this->result['msg'] = 'curl出现了错误';
                    return $this->result;
                }
                $curl_data['data'] = $curl_arr;
                $type = Config::get('collect.3');
        }else if ($reqData['act'] = 'man'){
                // 专家数据
                $request_arr = ['page'=>$page,'limit'=>$limit,'industry_id' => $reqData['industry_id'],'city_id' => $reqData['city_id'], 'organ_id' => $reqData['organ_id'], 'chain_id'=> $reqData['chain_id'], 'keywords'=>$keywords ];
                $curl_data = $this->getBusiness('Common')->curl_request_data($method,$request_arr);
                if ($curl_data['status'] != 1){
                    $this->result['status'] = $curl_data['status'];
                    $this->result['msg'] = $curl_data['msg'];
                    return json_encode($this->result);
                }
                $type = Config::get('collect.4');
        }else{
                $this->result['status'] = -1;
                $this->result['msg'] = '参数类型错误';
                return $this->result;
        }

        // 我的收藏字段
        $return_data = $this->getBusiness('Common')->clickCollet($dispatch,$curl_data['data']['data']['data'],$type);
        $curl_data['data']['data']['data'] = $return_data;

        $this->result['status'] = 1;
        $this->result['data'] = $curl_data['data']['data'];
        return json_encode($this->result);
    }

    /**
     * 智库详情
     */
    public function tankDetail(){
        $reqData['act'] = $this->request->get('act');
        $reqData['identification'] = $this->request->get('identification');
        $method = $this->request->method();
        $dispatch = $this->request->dispatch();

        if (!$reqData['identification']){
            $this->result['status'] = -1;
            $this->result['msg'] = '参数错误';
            return json_encode($this->result);
        }

        if ($reqData['act'] == 'organ'){
                // 机构数据
                $url = Config::get('cloude.url') .Config::get('cloude.Company')['companydetail'];
                $curl_arr  = httpRequest($url,$method,array('identification' => $reqData['identification']));
                if (!$curl_arr){
                    $this->result['status'] = -1;
                    $this->result['msg'] = 'curl出现了错误';
                    return $this->result;
                }
                $curl_data['data'] = $curl_arr;
                $type = Config::get('collect.3');
        }else if ($reqData['act'] == 'man'){
                // 专家数据
                $curl_data = $this->getBusiness('Common')->curl_request_data($method,array('identification' => $reqData['identification']));
                if ($curl_data['status'] != 1){
                    $this->result['status'] = $curl_data['status'];
                    $this->result['msg'] = $curl_data['msg'];
                    return json_encode($this->result);
                }
                $type = Config::get('collect.4');
        }else{
                $this->result['status'] = -1;
                $this->result['msg'] = '参数类型错误';
                return $this->result;
        }

        // 我的收藏字段
        $single = array($curl_data['data']['data']);
        $return_data = $this->getBusiness('Common')->clickCollet($dispatch,$single,$type);
        $curl_data['data']['data'] = $return_data;

        $this->result['status'] = 1;
        $this->result['msg'] = 'success';
        $this->result['data'] = $curl_data['data']['data'];
        return json_encode($this->result);
    }
}